<?php
namespace app\index\model;

use app\common\model\SuperModel;
use think\Request;

class Broadcast extends SuperModel
{


    public function _initialize()
    {
        parent::_initialize();
        $this->table = 'broadcast';
    }
    /**
     * 新建广播
     */
    public function doAdd(Request $request)
    {
        try {

            //拆分服务器
            $arr  = explode(",", $request->param('server_id'));
            $list = [];
            foreach ($arr as $server_id) {

                $rec['start_time']  = $request->param('start_time');
                $rec['end_time']    = $request->param('end_time');
                $rec['interval']    = $request->param('interval');
                $rec['content']     = $request->param('content');
                $rec['server']      = $server_id;
                $rec['create_time'] = date("Y-m-d H:i:s");

                array_push($list, $rec);
            }
            
            //新增保存
            $res = $this->allowField(true)
                ->saveAll($list);

            if ($res) {
                $output = array('success' => true, 'msg' => "新增成功！");
            } else {
                $output = array('success' => false, 'msg' => $this->getError());
            }

            //根据请求类型返回信息
            //
            return ($output);

        } catch (\Exception $e) {
            $this->doLog($e->getMessage());
            throw new \think\Exception('异常消息:' . $e->getMessage());
        }
    }

}
